# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/6 下午4:33
 @Author  : tgy
 
"""


class Wrapper:
    ...

    def __init__(self, cls):
        self.cls = cls
        self.count = 0

    def __call__(self, *args, **kwargs):
        self.count += 1
        print('count %d' % self.count)
        return self.cls(*args, **kwargs)


# 这种 装饰器更加通用，可以修饰类的方法，上面的不能修饰类方法
def wrapper(cls):
    ...
    # 使用这里定义的变量，替换类实例命名空间中的变量
    count = 0

    def call(*args, **kwargs):
        nonlocal count
        count += 1
        print('count %d' % count)
        return cls(*args, **kwargs)

    return call


@wrapper
class Person:
    ...


if __name__ == '__main__':
    ...
    person = Person()
    person = Person()
    person = Person()
